package com.winit.openapi.wh.allocation.builder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.allocation.vo.order.AllocationOrderMerchandiseVo;
import com.winit.oms.spi.inbound.vo.InboundMerchandiseDetailsVo;

public class AllocationOrderMerchandiseBuilder {

    /**
     * 构建商品列表
     * 
     * @param json
     * @return
     */
    public static List<Map<String, Object>> buildMerchandiseList(List<AllocationOrderMerchandiseVo> list) {
        List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
        for (AllocationOrderMerchandiseVo mvo : list) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("merchandiseId", mvo.getId());
            map.put("merchandiseCode", mvo.getMerchandiseCode());
            map.put("merchandiseSerno", mvo.getMerchandiseSerno());
            map.put("specification", mvo.getSpecification());
            map.put("suggestQty", mvo.getRecommendQty());
            map.put("expectQty", mvo.getExpectQty());
            map.put("boxQty", mvo.getBoxQty());
            map.put("qty", mvo.getEstimateDispatchQty());
            map.put("autalQty", mvo.getActualDispatchQty());
            map.put("nameCn", mvo.getNameCn());
            map.put("nameEn", mvo.getNameEn());
            mapList.add(map);
        }
        return mapList;
    }

	public static void buildMerchandiseVo(
			AllocationOrderMerchandiseVo merchandiseVo, JSONObject json) {
		merchandiseVo.setMerchandiseCode(json.getString("merchandiseCode")); 
		merchandiseVo.setSpecification(json.getString("specification"));
		merchandiseVo.setRecommendQty(json.getString("suggestQty").equals("") ? 0 : Integer.parseInt(json.getString("suggestQty")));
		merchandiseVo.setEstimateDispatchQty(json.getString("qty").equals("") ? 0 : Integer.parseInt(json.getString("qty")));
		merchandiseVo.setBoxQty(json.getString("boxQty").equals("") ? 0 :Integer.parseInt(json.getString("boxQty")));
	}

	public static void buildOrderVo(
			List<AllocationOrderMerchandiseVo> dumpMerchandiseList,
			JSONArray json) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * 
	 * 构建越库商品返回列表.
	 * @param merchandises
	 * @return
	 */
    public static List<Map<String, Object>> buildCrossMerList(List<InboundMerchandiseDetailsVo> merchandises) {
        List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
       
        for (InboundMerchandiseDetailsVo vo : merchandises) {
            Map<String, Object> newMer = new HashMap<String, Object>();
            newMer.put("merchandiseCode", vo.getMerchandiseCode());
            newMer.put("cnName", vo.getNameCn());
            newMer.put("specification", vo.getSpecification());
            newMer.put("enName", vo.getNameEn());
            newMer.put("merchandiseSerno", vo.getMerchandiseSerno());
            newMer.put("itemQty", vo.getActualQty());
            newMer.put("volume", vo.getVolume());
            newMer.put("weight", vo.getWeight());
            newMer.put("length", vo.getLength());
            newMer.put("width", vo.getWidth());
            newMer.put("height", vo.getHeight());
            newMer.put("id", vo.getInboundMerchandiseId());
            newMer.put("estimateItemQty", vo.getEstimateCrossDockQty());
            newMer.put("planItemQty", vo.getPlanItemQty());
            newMer.put("dayAvgSales", vo.getDayAvgSales());
            newMer.put("doi", vo.getDoi());
            newMer.put("usableQty", vo.getUsableQty());
            newMer.put("recommendQty", vo.getRecommendQty());
            list.add(newMer);
        }
        return list;
    }
}
